/**
 * HtmlFilter.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.presentacion.UtilidadesPresentacion;

import java.io.File;
import javax.swing.filechooser.FileFilter;


public class HtmlFilter extends FileFilter{

    String descripcion;
    String [] extensiones;

    public HtmlFilter(String descripcion, String [] extensiones){
        this.descripcion = descripcion;
        this.extensiones = extensiones;
    }

    public String getDescription(){
        return descripcion;
    }

    public boolean accept(File file){
        boolean resultado = false;
        if(file.isDirectory()){
            resultado = true;
        }else{
            String path = file.getAbsolutePath().toLowerCase();            
            for (int i = 0; i < extensiones.length; i++) {
                String extension = extensiones[i];
                int lugar = path.length()-extension.length();
                if (path.charAt(lugar-1) == '.' && path.substring(lugar,path.length()).equals(extension)) {
                    resultado = true;
                }
            }
        }
     return resultado;
    }

}
